;
(function (call) {
    var main = {
        userInfo: null,
        wpCfg: [{
            name: '晴',
            val: '00',
        }, {
            name: '多云',
            val: '01',
        }, {
            name: '阴',
            val: '02',
        }, {
            name: '阵雨',
            val: '03',
        }, {
            name: '雷阵雨',
            val: '04',
        }, {
            name: '雷阵雨并伴有冰雹',
            val: '05',
        }, {
            name: '雨夹雪',
            val: '06',
        }, {
            name: '阵雪',
            val: '13',
        }, {
            name: '雾',
            val: '18',
        }, {
            name: '冻雨',
            val: '19',
        }, {
            name: '沙尘暴',
            val: '20',
        }, {
            name: '浮尘',
            val: '29',
        }, {
            name: '扬沙',
            val: '30',
        }, {
            name: '强沙尘暴',
            val: '31',
        }, {
            name: '霾',
            val: '53',
        }, {
            name: '雨',
            val: '32',
        }, {
            name: '雪',
            val: '33',
        }],
        wsGradeCfg: [{
            name: '≤3级',
            val: '0',
            speedrg: '0.0~4.3'
        }, {
            name: '3~4级',
            val: '1',
            speedrg: '4.4~6.6'
        }, {
            name: '4~5级',
            val: '2',
            speedrg: '6.7~9.3'
        }, {
            name: '5~6级',
            val: '3',
            speedrg: '9.4~12.2'
        }, {
            name: '6~7级',
            val: '4',
            speedrg: '12.3~15.4'
        }, {
            name: '7~8级',
            val: '5',
            speedrg: '15.5~18.9'
        }, {
            name: '8~9级',
            val: '6',
            speedrg: '19.0~22.5'
        }, {
            name: '9~10级',
            val: '7',
            speedrg: '22.6~26.4'
        }, {
            name: '10~11级',
            val: '8',
            speedrg: '26.5~30.5'
        }, {
            name: '11~12级',
            val: '9',
            speedrg: '30.6~34.7'
        }],
        wdCfg: [{
            name: '北',
            val: '8'
        }, {
            name: '东北',
            val: '1'
        }, {
            name: '东',
            val: '2'
        }, {
            name: '东南',
            val: '3'
        }, {
            name: '南',
            val: '4'
        }, {
            name: '西南',
            val: '5'
        }, {
            name: '西',
            val: '6'
        }, {
            name: '西北',
            val: '7'
        }],
        init: function () {
            this.initView();
            this.bindEvt();
        },
        initView: function () {
            var userInfo = $("#userInfo").data('info');
            this.userInfo = userInfo;
            $(".today").text(new Date().format("MM月dd日"))
            var time = new Date();
            time.setDate(time.getDate() + 1);
            time = time.format("MM月dd日");
            $(".tomorrow").text(time);
            $("input").attr('autocomplete', 'off');
            this.initWpData();
            this.initwsGrade();
            this.initwd()
        },
        initWpData: function () {
            var $select = $(".wpSelect select").empty().append(`<option value=""></option>`);
            for (var i = 0; i < this.wpCfg.length; i++) {
                $select.append(`<option value="${this.wpCfg[i].val}">${this.wpCfg[i].name}</option>`)
            }
        },
        initwsGrade: function () {
            var $select = $(".wsGrade select").empty().append(`<option value=""></option>`);;
            for (var i = 0; i < this.wsGradeCfg.length; i++) {
                $select.append(`<option data-key="${this.wsGradeCfg[i].val}" value="${this.wsGradeCfg[i].speedrg}">${this.wsGradeCfg[i].name}</option>`)
            }
        },
        initwd: function () {
            var $select = $(".wdSelect select").empty().append(`<option value=""></option>`);;
            for (var i = 0; i < this.wdCfg.length; i++) {
                $select.append(`<option value="${this.wdCfg[i].val}">${this.wdCfg[i].name}</option>`)
            }
        },
        publishBigCityYb: function (falg) {
            var that = this;
            var productInfo = $(".task-menu-list li.active").data('product');
            var fortime = productInfo.fortime;
            var queryTime = new Date().format('yyyy-MM-dd 08:00:00')
            if (fortime == '15:45') {
                queryTime = new Date().format('yyyy-MM-dd 20:00:00')
            }
            var data = [{
                "stationId": "54517",
                "stationName": "天津城市气候监测站",
                "lon": "117.2",
                "lat": "39.07",
                "datas": [{
                    "aging": 6,
                    "tmax": $(".max1").val(),
                    "tmin": $(".min1").val(),
                    "wscode": $('#wsGrade1 option:selected').data('key'),
                    "wdcode": $("#wdSelect1").val(),
                    "wp": $("#wpSelect1").val(),
                    "rain": $(".rain1").val()
                }, {
                    "aging": 12,
                    "tmax": $(".max2").val(),
                    "tmin": $(".min2").val(),
                    "wscode": $('#wsGrade2 option:selected').data('key'),
                    "wdcode": $("#wdSelect2").val(),
                    "wp": $("#wpSelect2").val(),
                    "rain": $(".rain2").val()
                }, {
                    "aging": 18,
                    "tmax": $(".max3").val(),
                    "tmin": $(".min3").val(),
                    "wscode": $('#wsGrade3 option:selected').data('key'),
                    "wdcode": $("#wdSelect3").val(),
                    "wp": $("#wpSelect3").val(),
                    "rain": $(".rain3").val()
                }, {
                    "aging": 24,
                    "tmax": $(".max4").val(),
                    "tmin": $(".min4").val(),
                    "wscode": $('#wsGrade4 option:selected').data('key'),
                    "wdcode": $("#wdSelect4").val(),
                    "wp": $("#wpSelect4").val(),
                    "rain": $(".rain4").val()
                }]
            }]
            data = JSON.stringify(data)
            var params = 'stationName=' + '天津城市气候监测站' + '&falg=' + falg + '&forecasterId=' + that.userInfo.smuser.iid + '&product_id=' + productInfo.productId + '&fortime=' + fortime + '&queryTime=' + queryTime + '&jsonStr=' + data + ''
            $.ajax({
                url: api.internal.bigcityYb.pushBigCity,
                type: "POST",
                data: params,
                dataType: "json",
                success: function (res) {
                    if (res.isSuccess) {
                        if (falg != 0) {
                            alert("发布成功");
                        } else {
                            alert("保存成功");
                        }
                        CafeJS.menuFunc.setTask();
                    } else {
                        if (falg != 0) {
                            alert("发布失败")
                        } else {
                            alert("保存失败");
                        }
                    }
                },
            })
        },
        getWsGradeVal: function (fs) {
            var getValue = "";
            if (fs >= 0 && fs <= 4.3) {
                getValue = "≤3级";
            } else if (fs >= 4.4 && fs <= 6.6) {
                getValue = "3~4级";
            } else if (fs >= 6.7 && fs <= 9.3) {
                getValue = "4~5级";
            } else if (fs >= 9.4 && fs <= 12.2) {
                getValue = "5~6级";
            } else if (fs >= 12.3 && fs <= 15.4) {
                getValue = "6~7级";
            } else if (fs >= 15.5 && fs <= 18.9) {
                getValue = "7~8级";
            } else if (fs >= 19 && fs <= 22.5) {
                getValue = "8~9级";
            } else if (fs >= 22.6 && fs <= 26.4) {
                getValue = "9~10级";
            } else if (fs >= 26.5 && fs <= 30.5) {
                getValue = "10~11级";
            } else if (fs >= 30.6) {
                getValue = "11~12级";
            }
            return getValue;
        },
        bindEvt: function () {
            var that = this;
            $(".time_item").on("click", 'li', function () {
                $(this).addClass("active").siblings().removeClass("active");
            });
            $("#temp_icon").on("click", 'i', function () {
                $(this).toggleClass("active").siblings().removeClass("active");
            })
            $("#rain_icon").on("click", 'i', function () {
                $(this).toggleClass("active").siblings().removeClass("active");
            })
            $(".writing").on("click", 'span', function () {
                $(this).toggleClass("active").siblings().removeClass("active");
            })
            $("#ws_icon").on("click", 'i', function () {
                $(this).toggleClass("active").siblings().removeClass("active");
            })
            $(".wp_data").on("click", 'span', function () {
                $(this).toggleClass("active").siblings().removeClass("active");
            })
            $("#publishBtn").click(function () {
                that.publishBigCityYb(1);
            })
            $("#saveBtn").click(function () {
                that.publishBigCityYb(0);
            })
            $(".wsVal input").change(function () {
                var id = $(this).attr('id'),
                    val = $(this).val();
                var wsGrade = that.getWsGradeVal(val);
                var $select = $("#wsGrade" + id.charAt(id.length - 1))
                for (var i = 0; i < that.wsGradeCfg.length; i++) {
                    var wsObj = that.wsGradeCfg[i]
                    if (wsGrade === wsObj.name) {
                        $select.append(`<option selected data-key="${wsObj.val}" value="${wsObj.speedrg}">${wsObj.name}</option>`)
                    } else {
                        $select.append(`<option data-key="${wsObj.val}" value="${wsObj.speedrg}">${wsObj.name}</option>`)
                    }
                }
            })
        },
    };
    if (typeof call === 'function') {
        call(main);
    }
})(function (main) {
    main.init();
})